package com.red.wood.dubbo.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.red.wood.dubbo.dao.IrcsBusinessDataDao;

@Repository
public class IrcsBusinessDataDaoImpl implements IrcsBusinessDataDao{

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public List<Map<String, Object>> getIrcsDataInfo() {
		String sql = "select t.ircsid,t.ircsname,t.ircsadd,t.corp from t_dwd_ircs_ircsdata t";
		return jdbcTemplate.queryForList(sql);
	}

	@Override
	public List<Map<String, Object>> getIrcsHouseInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.houseid,t.housename,t.housetype,t.houseadd,t.housezip,t.houseprovince,t.housecity,t.housecounty");
		sql.append("                  from t_dwd_ircs_houseinfo t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsIpInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.startip,t.endip,t.type,t.sourceunit,t.allocationunit,t.allocationtime from t_dwd_ircs_ipinfo t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsBandWidthInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.bandwidth,t.linktype,t.accessunit,t.gatewayip,t.internetaccess from t_dwd_ircs_gatewayinfo t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsUserInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.userid,t.nature,t.unitname,t.idtype,t.idno,t.unitnature,t.officermobile,t.officertel,t.officeremail,t.address,t.registertime,t.zipcode from t_dwd_ircs_userinfo_result t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsDomainInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.userid,t.serviceid,t.domainid,t.domainname from t_dwd_ircs_user_service_domain t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsPublicDomainInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.domainid,t.domainname,t.domainlevel from t_dwd_ircs_publicdomaininfo t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsEmergencyContactInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.name,t.idtype,t.id,t.tel,t.mobile,t.email from t_dwd_ircs_emergencycontact t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsHouseOfficerInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.houseid,t.houseofficename,t.houseofficeidtype,t.houseofficeid,t.houseofficetel,t.houseofficemobile,t.houseofficeemail");
		sql.append("                  from t_dwd_ircs_house_officer t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}

	@Override
	public List<Map<String, Object>> getIrcsServiceInfo(int min, int max) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *");
		sql.append("  from (select a.*, rownum rn");
		sql.append("          from (select t.ircsid,t.userid,t.serviceid,t.servicecontent,t.regtype,t.regid,t.setmode from t_dwd_ircs_userinfo_service t) a");
		sql.append("         where rownum <= "+max+") aa");
		sql.append("  where rn > "+min);
		return jdbcTemplate.queryForList(sql.toString());
	}
}
